<template>
  <DaprPlusTable
    :table-title="$t('fsb.softwares.functionAuth.list')"
    :entity="entity"
    :grid-options="gridOptions"
    :form-options="formOptions"
    :query-api="crudApi.getPage"
    @update:grid-api="onGridApiUpdate"
  />
</template>

<script lang="ts" setup>
import type { ExtendedVxeGridApi, VxeGridProps } from '#/adapter/vxe-table';
import type { VbenFormProps } from '#/adapter/form';
import { DaprPlusTable } from '#/components/daprplus';
import { createCrudApi } from '#/api/daprplus';
import type { IOutDto, EntityInfo } from '#/utils/daprplus';
import { $t } from '#/locales';

const baseUrl = '/softwares/api/functionauth';
const crudApi = createCrudApi<never, FunctionAuthOutDto>(baseUrl);

const entity: EntityInfo = {
  code: 'FunctionAuth',
  display: $t('fsb.softwares.functionAuth.title'),
};

// 配置搜索表单
const formOptions: VbenFormProps = {
  collapsed: false,
  schema: [
    {
      component: 'Input',
      label: '功能名称',
      fieldName: 'functionName',
    },
    {
      component: 'Input',
      label: '用户名',
      fieldName: 'userName',
    },
    {
      component: 'Input',
      label: '昵称',
      fieldName: 'nickName',
    },
    {
      component: 'VbenDatePicker',
      label: '开始时间',
      fieldName: 'beginDate',
      componentProps: {
        type: 'datetime',
      },
    },
    {
      component: 'VbenDatePicker',
      label: '结束时间',
      fieldName: 'endDate',
      componentProps: {
        type: 'datetime',
      },
    },
  ],
  showCollapseButton: true,
  submitOnChange: true,
};

// 扩展配置
const gridOptions: VxeGridProps<FunctionAuthOutDto> = {
  columns: [
    {
      field: 'id',
      title: '编号',
      sortable: true,
      width: 130,
    },
    {
      field: 'functionName',
      title: '功能名称',
      sortable: true,
      align: 'left',
      minWidth: 150,
    },
    {
      field: 'userName',
      title: '用户名',
      sortable: true,
      align: 'left',
      minWidth: 150,
    },
    {
      field: 'nickName',
      title: '昵称',
      align: 'left',
      minWidth: 150,
    },
    {
      field: 'beginDate',
      title: '开始时间',
      formatter: 'formatDateTime',
      width: 150,
    },
    {
      field: 'endDate',
      title: '结束时间',
      formatter: 'formatDateTime',
      width: 150,
    },
    {
      field: 'createdTime',
      title: '创建时间',
      formatter: 'formatDateTime',
      width: 150,
    },
  ],
};

let gridApi: ExtendedVxeGridApi;

function onGridApiUpdate(api: ExtendedVxeGridApi) {
  gridApi = api;
}

export interface FunctionAuthOutDto extends IOutDto {
  functionName?: string;
  userName?: string;
  nickName?: string;
  beginDate?: Date | null;
  endDate?: Date | null;
  createdTime?: Date;
}
</script>

<style scoped></style>
